package crp.services.api.graphql.models;

import crp.core.academic.domain.models.AcademicTermEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.eclipse.microprofile.graphql.Id;
import org.eclipse.microprofile.graphql.Type;

import javax.validation.constraints.NotNull;
import java.time.OffsetDateTime;

@Type("AcademicTerm")
@Builder
@Getter
@AllArgsConstructor
public class AcademicTermPayload {
    @Id
    @NotNull
    private final String id;
    @NotNull
    private final String code;
    @NotNull
    private final String name;
    private final OffsetDateTime startAt;
    private final OffsetDateTime endAt;

    public static AcademicTermPayload of(AcademicTermEntity entity) {
        return AcademicTermPayload.builder()
                .id(entity.getId())
                .code(entity.getCode())
                .name(entity.getName())
                .startAt(entity.getStartAt())
                .endAt(entity.getEndAt())
                .build();
    }

    public static AcademicTermPayload empty() {
        return AcademicTermPayload.builder()
                .id("")
                .code("")
                .build();
    }
}
